using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Specialized;

namespace TFSWorkflowControl.Common
{
    public class Option
    {
        public string DefaultField { get; private set; }
        public List<string> FieldToIgnoreList { get; private set; }

        /// <summary>
        /// Initializes a new instance of the Option class.
        /// </summary>
        public Option()
        {
            FieldToIgnoreList = new List<string>();
        }

        public static Option ComputeOption(StringDictionary workItemOptions)
        {
            var result = new Option();
            if (workItemOptions != null)
            {
                foreach (var key in workItemOptions.Keys.OfType<string>())
                {

                    var value = workItemOptions[key] as string;

                    switch (key)
                    {
                        case "defaultfield":
                            result.DefaultField = value;
                            break;
                        case "ignorefields":
                            result.FieldToIgnoreList.AddRange(from field in value.Split(';')
                                                              let fieldName = field.Trim()
                                                              where fieldName.Length > 0
                                                              select fieldName);
                            break;
                        default:
                            continue;
                    }

                }
            }

            return result;
        }
    }
}
